﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace UbbTimetable2
{
    /// <summary>
    /// A struct to store day data.
    /// </summary>
    public struct Day
    {
        int _dayId;
        String _dayName;

        public int DayId
        {
            get { return _dayId; }
            set { _dayId = value; }
        }

        public String DayName
        {
            get { return _dayName; }
            set { _dayName = value; }
        }
    }

    /// <summary>
    /// A DAO that handles all data related to days.
    /// </summary>
    public class DayDao: Dao
    {
        private String err = "";

        /// <summary>
        /// The last error message.
        /// </summary>
        public String Err
        {
            get { return err; }
        }

        /// <summary>
        /// Returns the list of days.
        /// </summary>
        /// <returns>The list of days.</returns>
        public List<Day> GetDayList()
        {
            String query = "SELECT * FROM Nap";
            SqlDataReader rdr = ExecuteReader(query, ref err);

            List<Day> list = new List<Day>();
            if (err == "OK")
            {
                while (rdr.Read())
                {
                    Day item = new Day();
                    item.DayId = Convert.ToInt32(rdr[0]);
                    item.DayName = rdr[1].ToString().TrimEnd();

                    list.Add(item);
                }
            }
            CloseDataReader(rdr);
            return list;
        }
    }
}
